package com.grizz.snake;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import com.grizz.snake.controller.Mediator;
import com.grizz.snake.controller.factory.MediatorFactory;

public class Game extends BasicGame{
	private Mediator mediator;
	private boolean isPaused;
	private boolean isGameOver;
	
	public Game() {
		super("Testowe okno");
	}

	@Override
	public void init(GameContainer container) throws SlickException {
		mediator = new MediatorFactory().getFullySetUpMediator(this);
	}

	@Override
	public void render(GameContainer container, Graphics g)
			throws SlickException {
		if(!isGameOver){
			mediator.drawMap();
			mediator.drawSnake();
			mediator.drawFood();
			if(isPaused)
				drawPause(g);
		}else{
			drawGameOver(g);
		}
	}

	private void drawGameOver(Graphics g) {
		g.drawString("GAME OVER!", 200, 300);
	}

	private void drawPause(Graphics g) {
		g.drawString("Paused", 200, 300);
	}

	@Override
	public void update(GameContainer container, int delta)
			throws SlickException {
		mediator.update(container, delta);
	}

	public boolean isPaused() {
		return isPaused;
	}

	public void setPause(boolean isPaused) {
		this.isPaused = isPaused;
	}

	public void gameOver() {
		isPaused = true;
		isGameOver = true;
	}

	public void startGame() {
		isPaused = false;
		isGameOver = false;
	}
	
	public static void main(String[] args) throws SlickException {
		AppGameContainer container = new AppGameContainer(new Game(), 480, 640, false);
		container.start();
	}
}
